package com.my.test.thread.executors;

import com.my.test.thread.callable.MyCallable;
import com.my.test.thread.runnable.MyRunnable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class TestExecutors {


    private static ExecutorService es = Executors.newFixedThreadPool(10);


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        es.execute(()-> {
            System.out.println("执行");
        });

        System.out.println("==============execute=============");

        Future<String> future = es.submit(new MyCallable());
        System.out.println(future.get());

        System.out.println("==============submit(Callable<T> task)=============");
        MyRunnable able = new MyRunnable();
        Future<MyRunnable> future2 = (Future<MyRunnable>) es.submit(able);
        MyRunnable runs = future2.get();
        System.out.println(runs.name);
        System.out.println(able.name);
        System.out.println("==============submit(Runnable task)=============");

        /*Data data = new Data();
        MyRunnable run = new MyRunnable(data);
        Future<Data> future3 = es.submit(run,data);
        System.out.println("future"+future3.get().getAge());
        System.out.println(""+run.getData().getAge());
        System.out.println("==============submit(Runnable task, T result)=============");*/

        es.shutdown();
    }
}
